using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Collections.Generic;
using ESOL.Common.Entity;
using System.Data;
using ESOL.Business.Mst;

namespace ESOL.WinUI.Hr
{
    public partial class frmPrintTemplateFormalApplication : DevExpress.XtraReports.UI.XtraReport
    {
        private List<HrFormalApplicationEntity> mFormalApplication;
        public frmPrintTemplateFormalApplication()
        {
            InitializeComponent();
        }

        public frmPrintTemplateFormalApplication(List<HrFormalApplicationEntity> list)
        {
            InitializeComponent();
            mFormalApplication = list;

            DataTable dt = new DataTable();
            dt.Columns.Add("PERSON");
            dt.Columns.Add("DEPARTMENT");
            dt.Columns.Add("POSITION");
            dt.Columns.Add("APPLICATIONDATE");
            dt.Columns.Add("FORMALREASON");
            dt.Columns.Add("DMREMARK");
            dt.Columns.Add("DMPERSON");
            dt.Columns.Add("DMAPPROVEDATE");
            dt.Columns.Add("HRREMARK");
            dt.Columns.Add("HRPERSON");
            dt.Columns.Add("HRAPPROVEDATE");
            dt.Columns.Add("CEOREMARK");
            dt.Columns.Add("CEOPERSON");
            dt.Columns.Add("CEOAPPROVEDATE");
            dt.Columns.Add("REMARK");

            foreach (HrFormalApplicationEntity formal in mFormalApplication )
            {
                DataRow dr = dt.NewRow();

                MstDepartmentEntity department = MstDepartmentBs.GetMstDepartmentByID(formal.DepartmentId);
                if (department != null)
                {
                    dr["DEPARTMENT"] = department.DepartmentName;
                }
                MstPersonEntity person = MstPersonBs.GetMstPersonByID(formal.PersonId);
                if (person != null)
                {
                    dr["PERSON"] = person.NameCn;
                }
                MstPositionEntity position = MstPositionBs.GetMstPositionByID(formal.PositionId);
                if (position != null)
                {
                    dr["POSITION"] = position.PositionName;
                }
                dr["APPLICATIONDATE"] = formal.ApplicationDate.ToString("yyyy-MM-dd");
                dr["FORMALREASON"] = formal.FormalReason;
                dr["DMREMARK"] = formal.DmRemark;

                MstPersonEntity dmPerson = MstPersonBs.GetMstPersonByID(formal.DmPerson);
                dr["DMPERSON"] = dmPerson.NameCn;

                if (formal.DmApprovedDate.ToString("yyyy-MM-dd") != "0001-01-01" && formal.DmApprovedDate.ToString("yyyy-MM-dd") != "1900-01-01")
                {
                    dr["DMAPPROVEDATE"] = formal.DmApprovedDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    dr["DMAPPROVEDATE"] = "";
                }
                dr["HRREMARK"] = formal.HrRemark;
                MstPersonEntity hrPerson = MstPersonBs.GetMstPersonByID(formal.HrPerson);
                if (hrPerson != null)
                {
                    dr["HRPERSON"] = hrPerson.NameCn;
                }
                if (formal.HrApprovedDate.ToString("yyyy-MM-dd") != "0001-01-01" && formal.HrApprovedDate.ToString("yyyy-MM-dd") != "1900-01-01")
                {
                    dr["HRAPPROVEDATE"] = formal.HrApprovedDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    dr["HRAPPROVEDATE"] = "";
                }
                dr["CEOREMARK"] = formal.CeoRemark;
                MstPersonEntity ceoPerson = MstPersonBs.GetMstPersonByID(formal.CeoPerson);
                if (ceoPerson != null)
                {
                    dr["CEOPERSON"] = ceoPerson.NameCn;
                }
                if (formal.CeoApprovedDate.ToString("yyyy-MM-dd") != "0001-01-01" && formal.CeoApprovedDate.ToString("yyyy-MM-dd") != "1900-01-01")
                {
                    dr["CEOAPPROVEDATE"] = formal.CeoApprovedDate.ToString("yyyy-MM-dd");
                }
                else
                {
                    dr["CEOAPPROVEDATE"] = "";
                }
                dr["REMARK"] = formal.Remark;

                dt.Rows.Add(dr);
            }
            this.DataSource = dt;
            xtcPerson.DataBindings.Add("Text", dt, "PERSON");
            xtcDepartment.DataBindings.Add("Text", dt, "DEPARTMENT");
            xtcPosition.DataBindings.Add("Text", dt, "POSITION");
            xtcApplicationDate.DataBindings.Add("Text", dt, "APPLICATIONDATE");
            xtcFormalReason.DataBindings.Add("Text", dt, "FORMALREASON");
            xtcDmRemark.DataBindings.Add("Text", dt, "DMREMARK");
            xtcDmPerson.DataBindings.Add("Text", dt, "DMPERSON");
            xtcDmApprovedDate.DataBindings.Add("Text", dt, "DMAPPROVEDATE");
            xtcHrRemark.DataBindings.Add("Text", dt, "HRREMARK");
            xtcHrPerson.DataBindings.Add("Text", dt, "HRPERSON");
            xtcHrApprovedDate.DataBindings.Add("Text", dt, "HRAPPROVEDATE");
            xtcCeoRemark.DataBindings.Add("Text", dt, "CEOREMARK");
            xtcCeoPerson.DataBindings.Add("Text", dt, "CEOPERSON");
            xtcCeoApprovedDate.DataBindings.Add("Text", dt, "CEOAPPROVEDATE");
            xtcRemark.DataBindings.Add("Text", dt, "REMARK");
        }
    }
}
